import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _create_class } from "@swc/helpers/_/_create_class";
import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
import OAuth2Window, { detectMob, loadJS, toQuery } from "./utils";
import { QQ_APPID } from "./config";
var QQAuth = /*#__PURE__*/ function _target() {
    "use strict";
    function QQAuth() {
        var _this = this;
        _class_call_check(this, QQAuth);
        _define_property(this, "load", false);
        _define_property(this, "getCode", function() {
            return new Promise(function(resolve, reject) {
                /** qq  申请的回调地址为 complete/qq   */ //   const test = window.QC?.Login.showPopup({
                //     appId: QQ_APPID,
                //     redirectURI: "https://www.qieryideas.com/complete/qq",
                //   });
                OAuth2Window.open("qq", "https://graph.qq.com/oauth2.0/authorize?".concat(toQuery({
                    response_type: "code",
                    client_id: QQ_APPID,
                    redirect_uri: "https://www.qieryideas.com/complete/qq",
                    scope: "get_user_info",
                    display: detectMob() ? "mobile" : "pc",
                    state: ""
                })), {
                    width: "600",
                    height: "600"
                }).then(function(res) {
                    console.log(res);
                    resolve({
                        code: res.code,
                        state: res.state
                    });
                }, reject);
            });
        });
        _define_property(this, "getAccessToken", function() {
            return new Promise(function(resolve, reject) {
                try {
                    _this.getCode().then(function(res) {
                        var code = res.code;
                    });
                } catch (err) {
                    reject(err);
                }
            });
        });
        if ((_instanceof(this, QQAuth) ? this.constructor : void 0) !== QQAuth) {
            return;
        }
        if (!QQAuth._instance) {
            QQAuth._instance = this;
        }
        /** 加载sdk */ this.loadSdk();
        return QQAuth._instance;
    }
    _create_class(QQAuth, [
        {
            key: "loadSdk",
            value: function loadSdk(cb, onError) {
                var _this = this;
                loadJS("https://connect.qq.com/qc_jssdk.js", function() {
                    _this.load = true;
                }, function() {
                    var _this1, _this_onError;
                    onError === null || onError === void 0 ? void 0 : onError();
                    (_this_onError = (_this1 = _this).onError) === null || _this_onError === void 0 ? void 0 : _this_onError.call(_this1);
                });
            }
        },
        {
            key: "init",
            value: function init() {
                var _this = this;
                /** 假如 sdk 加载失败可以使用init 重新加载sdk */ return new Promise(function(resolve, reject) {
                    if (_this.load && window.QC) {
                        resolve(QQAuth._instance);
                        return;
                    }
                    _this.loadSdk(function() {
                        resolve(QQAuth._instance);
                    }, reject);
                });
            }
        }
    ], [
        {
            key: "getInstance",
            value: function getInstance() {
                if (!QQAuth._instance) {
                    QQAuth._instance = new QQAuth();
                }
                return QQAuth._instance;
            }
        }
    ]);
    return QQAuth;
}();
_define_property(QQAuth, "_instance", null);
export default QQAuth.getInstance();

 //# sourceMappingURL=qq.js.map